[][src]Crate scale_info

Efficient and compact serialization of Rust types.

This library provides structures to easily retrieve compile-time type information at runtime and also to serialize this information in a compact form.

Registry

At the heart of its functionality is the Registry that acts as cache for known types in order to efficiently deduplicate them and thus compactify the overall serialization.

Type Information

Information about types is provided via the TypeInfo trait.

This trait should be implemented for all types that are serializable. For this the library provides implementations for all commonly used Rust standard types and provides derive macros for simpler implementation of user provided custom types.

Compaction Forms

There is an uncompact form, called MetaForm that acts as a bridge from compile-time type information at runtime in order to easily retrieve all information needed to uniquely identify types.

The compact form is retrieved by the IntoCompact trait and internally used by the Registry in order to convert the uncompact types into their compact form.

Symbols and Namespaces

To differentiate two types sharing the same name namespaces are used. Commonly the namespace is equal to the one where the type has been defined in. For Rust prelude types such as Option and Result the root namespace (empty namespace) is used.

To use this library simply use the MetaForm initially with your own data structures and at best make them generic over the Form trait just as has been done in this crate with TypeInfo in order to go for a simple implementation of IntoCompact. Use a single instance of the Registry for compaction and provide this registry instance upon serialization. Done.

A usage example can be found in ink! here: https://github.com/paritytech/ink/blob/master/abi/src/specs.rs

Modules

build

Builders for defining metadata for variant types (enums), and composite types (structs). They are designed to allow only construction of valid definitions.

form

Provides some form definitions.

interner

Interning data structure and associated symbol definitions.

Macros

tuple_meta_type

Takes a number of types and returns a vector that contains their respective MetaType instances.

Structs

Field

A field of a struct like data type.

MetaType

A metatype abstraction.

Path

Represents the path of a type definition.

Registry

The registry for compaction of type identifiers and definitions.

RegistryReadOnly

A read-only registry, to be used for decoding/deserializing

Type

A Type definition with optional metadata.

TypeDefArray

An array type.

TypeDefComposite

A composite type, consisting of either named (struct) or unnamed (tuple struct) fields

TypeDefSequence

A type to refer to a sequence of elements of the same type.

TypeDefTuple

A type to refer to tuple types.

TypeDefVariant

A Enum type (consisting of variants).

Variant

A struct enum variant with either named (struct) or unnamed (tuple struct) fields.

Enums

PathError

An error that may be encountered upon constructing namespaces.

TypeDef

The possible types a SCALE encodable Rust value could have.

TypeDefPrimitive

A primitive Rust type.

Traits

IntoCompact

Compacts the implementor using a registry.

TypeInfo

Implementors return their meta type information.

Functions

meta_type

Returns the runtime bridge to the types compile-time type information.